package com.ss.android.article.share.a;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ss.android.article.browser.R;
import com.ss.android.article.share.e.b;
import com.ss.android.article.share.ui.RecyclerViewWrapper.d;
import com.ss.android.image.AvatarLoader;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public final class a extends com.ss.android.article.share.ui.RecyclerViewWrapper.a implements View.OnClickListener {
    public final class a$a extends com.ss.android.article.share.ui.RecyclerViewWrapper.d {
        public ImageView a;
        public TextView b;

        public a$a(View arg2) {
            super(arg2);
            this.a = arg2.findViewById(com.ss.android.article.browser.R.id.icon);
            this.b = arg2.findViewById(com.ss.android.article.browser.R.id.text);
        }
    }

    private LayoutInflater c;
    private List d;
    private Resources e;
    private b f;
    private AvatarLoader g;

    public a(Context arg2, List arg3, b arg4, AvatarLoader arg5) {

        this.d = new ArrayList();
        this.c = LayoutInflater.from(arg2);
        this.e = arg2.getResources();
        if (arg3 != null && !arg3.isEmpty()) {
            this.d.addAll(((Collection) arg3));
        }

        this.f = arg4;
        this.g = arg5;
    }

    private com.ss.android.article.share.entity.a a(int arg2) {
        Object v0;
        if (arg2 < 0 || arg2 >= this.d.size()) {
            v0 = null;
        } else {
            v0 = this.d.get(arg2);
        }
        return ((com.ss.android.article.share.entity.a) v0);
    }

    public final int a() {
        return this.d.size();
    }

    public final d a(ViewGroup arg4) {
        View v0 = this.c.inflate(com.ss.android.article.browser.R.layout.c4, arg4, false);
        if (this.f != null) {
            v0.setOnClickListener(((View.OnClickListener) this));
        }

        return new a$a(v0);
    }

    public final void a(d arg9, int arg10) {
        com.ss.android.article.share.entity.a v0 = this.a(arg10);
        if (v0 != null) {
            com.ss.android.j.b.isNightModeToggled();
            if (v0.a != 0) {
                try {
                    ((a$a) arg9).a.setImageResource(v0.a);
                } catch (Exception v1) {
                }

                if (((a$a) arg9).a.getDrawable() != null && (((a$a) arg9).a.getDrawable().isStateful())) {
//                    goto label_49;
                } else {
                    Drawable v1_1 = DrawableCompat.wrap(VectorDrawableCompat.create(((a$a) arg9).a.getResources(), v0.a, new ContextThemeWrapper(((a$a) arg9).a.getContext(), R.style.cw).getTheme()));
                    Drawable v2 = DrawableCompat.wrap(VectorDrawableCompat.create(((a$a) arg9).a.getResources(), v0.a, new ContextThemeWrapper(((a$a) arg9).a.getContext(), R.style.cv).getTheme()));
                    StateListDrawable v3 = new StateListDrawable();
                    v3.addState(new int[]{16842913}, v1_1);
                    v3.addState(new int[0], v2);
                    ((a$a) arg9).a.setImageDrawable(((Drawable) v3));
                }
            }

//        label_49:
            if (v0.b > 0) {
                ((a$a) arg9).b.setText(v0.b);
            } else {
                ((a$a) arg9).b.setText(v0.d);
            }

            ((a$a) arg9).b.setTextColor(this.e.getColorStateList(com.ss.android.article.browser.R.color.zi1));
            ((a$a) arg9).c.setSelected(v0.f);
            ((a$a) arg9).c.setTag(arg9);
            if (v0.e == 12) {
                ((a$a) arg9).a.setPadding(0, 0, 0, 0);
                if (this.g != null) {
                    this.g.loadAvatar(((a$a) arg9).a, v0.c);
                } else {
                    return;
                }
            }

            ((a$a) arg9).a.setColorFilter(null);
        }
    }

    public final void onClick(View arg4) {
        Object v0 = arg4.getTag();
        if (this.f != null && ((v0 instanceof a$a))) {
            com.ss.android.article.share.entity.a v0_1 = this.a(((d) v0).d);
            if (v0_1 != null) {
                this.f.a(v0_1, arg4, null);
            }
        }
    }
}

